<?php
namespace Mobile\Controller;
use Think\Controller;
use Lib\Cate\Level;
/**
 * 列表控制器
 */
class ListController extends CommonController{
	public function index(){
		$id = I('get.id','','int');
		
		$cate = M('category')->order('sort')->select();
		$cids = Level::getChildsId($cate,$id);
		$cids[] = $id;

		$count = D('BlogView')->where(array('del'=>0,'cid'=> array('IN',$cids)))->count();
		$Page = new \Think\Page($count,5);
		$limit = $Page->firstRow.','.$Page->listRows;
		$Page->setConfig('prev','<');
		$Page->setConfig('next','>');
		$Page->setConfig('first','<<');
		$Page->setConfig('last','>>');
		$Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
		$this->page = $Page->show();
		
		$this->list = D('BlogView')->listBlogs($cids,$limit);

		$this->cateChilds = M('category')->field(array('id','name'))->where(array('pid'=>$id))->order('sort')->select();
		$this->cateName = M('category')->where(array('id'=>$id))->getField('name');
		$this->display();
	}
	public function moodlist(){
		$db = M('talk');
		$count = $db->count();
		$pagesize = 5;
		$Page = new \Think\Page($count,$pagesize);
		$limit = $Page->firstRow.','.$Page->listRows;
		$Page->setConfig('prev','<');
		$Page->setConfig('next','>');
		$Page->setConfig('first','<<');
		$Page->setConfig('last','>>');
		$Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
		$this->page  = $Page->show();

		$this->talk = $db->limit($limit)->select();
		$this->display();
	}
	public function search(){
		$type = I('type');
		if(!I('content')){
			$this->error('必须输入关键字才能查询,请重试...');
		}else{
			$content = I('content');
		}
		$count = M('Blog')->where(array($type=>array('like',"%".$content."%"),'del'=>0))->count();
		$Page = new \Think\Page($count,4);
		$limit = $Page->firstRow.','.$Page->listRows;
		$Page->setConfig('prev','<');
		$Page->setConfig('next','>');
		$Page->setConfig('first','<<');
		$Page->setConfig('last','>>');
		$Page->setConfig('header','共<a style="background:#000;color:#fff;">%TOTAL_ROW%</a>条&nbsp;&nbsp;');
		$Page->setConfig('theme','%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
		$this->page = $Page->show();

		$this->list = D('BlogView')->searchBlogs($limit,$type,$content);

		$this->display();
	}
}